<!DOCTYPE html>
<html>
  <head>
    <script src="../../../../../processing.js"></script>
    <link rel="stylesheet" href="../../../../style.css" />
  </head> 

  <body> 
    <h1><a href="http://asalga.wordpress.com">Andor Salga</a></h1>
    <h2>Bird demo for rect 3D</h2>

    <p>This page demonstrates the Pjs rect() function.<br />
    <br />
    </p>

    <p>
      <canvas datasrc="bird.pjs"> </canvas>
    </p>
    
    <pre><b>// Example from Processing.org</b>
    
import processing.opengl.*;

float ang = 0, ang2 = 0, ang3 = 0, ang4 = 0;
float px = 0, py = 0, pz = 0;
float flapSpeed = 0.2;

void setup(){
  size(640,360,OPENGL);
  noStroke();
}

void draw(){
  background(0);
  camera();
  lights();

  // Flight
  px = sin(radians(ang3)) * 170;
  py = cos(radians(ang3)) * 300;
  pz = sin(radians(ang4)) * 500;
  translate(width/2 + px, height/2 + py, -700+pz);
  rotateX(sin(radians(ang2)) * 120);
  rotateY(sin(radians(ang2)) * 50);
  rotateZ(sin(radians(ang2)) * 65);
  
  // Body
  fill(153);
  box(20, 100, 20);
  
  // Left wing
  fill(204);
  pushMatrix();
  rotateY(sin(radians(ang)) * -20);
  rect(-75, -50, 75, 100);
  popMatrix();

  // Right wing
  pushMatrix();
  rotateY(sin(radians(ang)) * 20);
  rect(0, -50, 75, 100);
  popMatrix();

  // Wing flap
  ang += flapSpeed;
  if (ang > 3) {
    flapSpeed *= -1;
  } 
  if (ang < -3) {
    flapSpeed *= -1;
  }

  // Increment angles
  ang2 += 0.01;
  ang3 += 2.0;
  ang4 += 0.75;
}</pre>

  </body>
</html>
